import type { RouteRecordRaw } from 'vue-router'
import { createRouter, createWebHistory } from 'vue-router'

// 定义路由记录，这些路由将对应不同的模块页面
const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'home',
    redirect: '/tenant', // 默认重定向到租客管理页面
  },
  {
    path: '/tenant',
    name: 'tenant',
    component: () => import('../views/tenant/TenantManagement.vue'),
    meta: {
      title: '租客管理',
    },
  },
  {
    path: '/room',
    name: 'room',
    component: () => import('../views/room/RoomManagement.vue'),
    meta: {
      title: '房间管理',
    },
  },
  {
    path: '/cleaning',
    name: 'cleaning',
    component: () => import('../views/cleaning/CleaningManagement.vue'),
    meta: {
      title: '卫生管理',
    },
  },
  {
    path: '/price',
    name: 'price',
    component: () => import('../views/price/PriceManagement.vue'),
    meta: {
      title: '房价管理',
    },
  },
  {
    path: '/report',
    name: 'report',
    component: () => import('../views/report/ReportCenter.vue'),
    meta: {
      title: '报表中心',
    },
  },
  {
    path: '/user',
    name: 'user',
    component: () => import('../views/user/UserList.vue'),
    meta: {
      title: '用户管理',
    },
  }
]

// 创建路由实例
const router = createRouter({
  history: createWebHistory(),
  routes,
})

// 全局前置守卫，用于设置页面标题
router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title as string
  }
  next()
})

export default router